package com.exam.bytedance;

/**
 * date:
 * description:
 */
public class Solution001 {
    public static void main(String[] args) {
        boolean res = isMatch("ahjkb", "a*bb");
        System.out.println(res);
    }

    public static boolean isMatch(String str, String pattern){
        int len1 = str.length();
        int len2 = pattern.length();
        boolean[][] dp = new boolean[len1 + 1][len2 + 1];
        dp[0][0] = true;
        for (int i = 1; i <= len1; i++) {
            for (int j = 1; j <= len2; j++) {
                if(pattern.charAt(j - 1) == '?'){
                    dp[i][j] = dp[i - 1][j - 1];
                }else if(pattern.charAt(j - 1) == '*'){
//                    三种情况：不参与匹配，参与匹配且只匹配当前字符，参与匹配且匹配了之前的字符
                    dp[i][j] = dp[i - 1][j - 1] || dp[i - 1][j] || dp[i][j - 1];
                }else{
                    if(str.charAt(i - 1) == pattern.charAt(j - 1)){
                        dp[i][j] = dp[i - 1][j - 1];
                    }
                }
            }
        }
        return dp[len1][len2];
    }

}
